<?php
	$file = fopen('summary.txt','r');
	$patternLvl1 = "/[']*\[ [0-9][']*[ ]*[']*(([\w-&:,\/][ ]?)+)[ ]*[0-9]+\]/";
	$patternLvl2 = "/[']*\[ [0-9]([.][0-9])?[']*[ ]*[']*(([\w-&:,\/][ ]?)+)[ ]*[0-9]+\]/";
	$patternLvl3 = "/[']*\[ [0-9]([.][0-9])*[']*[ ]*[']*(([\w-&:,\/][ ]?)+)[ ]*[0-9]+\]/";
	$patternAnnexe ="/[']*\[ (([\w][ ]?)+)[ ]*[A-z]\]/";
	$patternAnnexe1 ="/[']*\[ [A-Z][.][ ]*(([\w\/()][ ]?)+)[ ]*[A-Z]\]/";
	$headers = array();
	while (($line = fgets($file)) !== false) {
		if($line!="\r\n"){
			if(preg_match($patternLvl1, $line, $matchs)){
				$curr = strtoupper($matchs[1]);
				$headers[$curr]=array();
			}else{
				if(preg_match($patternAnnexe, $line, $matchs)){
					$curr = $matchs[1];
					$headers[$curr]=array();
				}else{
					if(preg_match($patternLvl2, $line, $matchs)){
						$curr1 = strtoupper($matchs[2]);
						$headers[$curr][$curr1]= array();
					}else{
						if(preg_match($patternAnnexe1, $line, $matchs)){
							$curr1 = strtoupper($matchs[1]);
							$headers[$curr][$curr1]= array();
						}else{
							if(preg_match($patternLvl3, $line, $matchs)){
								$curr2 = $matchs[2];
								$headers[$curr][$curr1][$curr2]= array();
							}
						}
					}
				}
			}
    }
  }
  echo json_encode($headers);
